package com.jzy.gulimall.order.vo;

import cn.hutool.core.collection.CollectionUtil;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author jzy
 * @date 2020/9/20 16:08
 * 订单确认页需要的数据
 */
public class OrderConfirmVo {

    //收货地址
    @Getter @Setter
    private List<MemberAddressVo> memberAddressVos;

    //所有选中的购物项
    @Getter @Setter
    private List<OrderCartItemVo> orderCartItemVos;

    //发票信息

    //优惠卷信息
    @Getter @Setter
    private Integer integration; //会员积分

    //private BigDecimal total;   //总额

    //private BigDecimal payPrice; //应付

    public BigDecimal getTotal() {
        BigDecimal decimal = new BigDecimal(0);
        //购物项总价
        if (CollectionUtil.isNotEmpty(orderCartItemVos)) {
            for (OrderCartItemVo itemVo : orderCartItemVos) {
                decimal = decimal.add(itemVo.getPrice().multiply(new BigDecimal(itemVo.getCount())));
            }
        }
        //减去优惠价格
        return decimal;
    }

    public BigDecimal getPayPrice(){
        return getTotal();
    }

    //防止重复提交订单
    @Getter @Setter
    private String orderToken;

    //private Integer countNum; //商品数量

    /**
     * 获取商品总数量
     */
    public Integer getCountNum() {
        int count = 0;
        if (CollectionUtil.isNotEmpty(orderCartItemVos)) {
            for (OrderCartItemVo itemVo : orderCartItemVos) {
                count += itemVo.getCount();
            }
        }
        return count;
    }

    @Getter @Setter
    private Map<Long, Boolean> hasStock;    //是否有货
}
